<?php defined('SYSPATH') or die('No direct script access.');
 
class Model_Services extends ORM {
	protected $_table_name = 'services';

	public function forMain($postfix) {
		return DB::select('id', array('title'.$postfix, 'title'), array('description'.$postfix, 'description'), 'price')
			->from($this->_table_name)
			->order_by('sort', 'DESC')
			->limit(12)
			->as_object()
			->execute();
	}

	public function getOne($postfix, $id) {
		return DB::select('id', array('title'.$postfix, 'title'), array('description'.$postfix, 'description'), 'price')
			->from($this->_table_name)
			->where('id', '=', $id)
			->as_object()
			->execute()
			->current();
	}

	public function getAll($postfix, $offset) {
		$items_per_page = Kohana::$config->load('main')->items_per_page;

		return DB::select('id', array('title'.$postfix, 'title'), array('description'.$postfix, 'description'), 'price')
			->from($this->_table_name)
			->order_by('sort', 'DESC')
			->limit($items_per_page)
			->offset($offset)
			->as_object()
			->execute();
	}

	public function forSelect($postfix, $offset) {
		$items_per_page = Kohana::$config->load('main')->items_per_page;

		return DB::select('id', array('title'.$postfix, 'title'), array('description'.$postfix, 'description'), 'price')
			->from($this->_table_name)
			->order_by('sort', 'DESC')
			->limit($items_per_page)
			->offset($offset)
			->execute()
			->as_array('id', 'title');
	}

}